﻿#pragma once

#include "Types.h"

#include <unordered_map>
#include <string>

namespace Lisp
{
  class Env;
  using EnvPtr = RefCountedPtr<Env>;

  class Env : public RefCounted
  {
  public:
    Env(EnvPtr outer = nullptr) : m_outer(outer) {};  
    Env(EnvPtr outer, const std::vector<std::string> &bindings, ListPtr args);
    ~Env() {};

    ValPtr Get(const std::string &name);
    ValPtr Set(const std::string &name, ValPtr value);
    EnvPtr Find(const std::string &name);
    EnvPtr GetRoot();

  private:
    typedef std::unordered_map<std::string, ValPtr> EnvMap;

    EnvMap m_env;
    EnvPtr m_outer; // 外层作用域环境
  };

  

}